#ifndef __CACHE_H__
#define __CACHE_H__

#define CACHEL1_BLSIZE_BIT 6//块存储位为6
#define CACHEL1_WAY_BIT 3//8路
#define CACHEL1_SET_BIT 7//组数位
#define CACHEL1_BLSIZE (1<<CACHEL1_BLSIZE_BIT)
#define CACHEL1_WAYSIZE (1<<CACHEL1_WAY_BIT)
#define CACHEL1_SETSIZE (1<<CACHEL1_SET_BIT)
#define CACHEL1_BLMASK (CACHEL1_BLSIZE-1)
#define CACHEL1_WAYMASK (CACHEL1_WAYSIZE-1)
#define CACHEL1_SETMASK (CACHEL1_SETSIZE-1)

#define CACHEL2_BLSIZE_BIT 6
#define CACHEL2_WAY_BIT 4
#define CACHEL2_SET_BIT 12
#define CACHEL2_BLSIZE (1 << CACHEL2_BLSIZE_BIT)
#define CACHEL2_WAYSIZE (1 << CACHEL2_WAY_BIT)
#define CACHEL2_SETSIZE (1 << CACHEL2_SET_BIT)
#define CACHEL2_BLMASK (CACHEL2_BLSIZE-1)
#define CACHEL2_WAYMASK (CACHEL2_WAYSIZE-1)
#define CACHEL2_SETMASK (CACHEL2_SETSIZE-1)

typedef struct {
	uint8_t data[CACHEL1_BLSIZE];//CACHEL1_BLSIZE大小的块
	uint32_t tag;//标志位
	bool valid;//有效位
} cachel1_bl;//cache块
cachel1_bl cache1[CACHEL1_WAYSIZE*CACHEL1_SETSIZE];//利用一维数组进行存储

typedef struct {
	uint8_t data[CACHEL2_BLSIZE];
	uint32_t tag;
	bool valid;
    bool dirty;//脏位
} cachel2_bl;
cachel2_bl cache2[CACHEL2_WAYSIZE*CACHEL2_SETSIZE];//

void add_time(uint32_t tm);
int cache1_read(hwaddr_t addr);
int cache2_read(hwaddr_t addr);
void cache1_write(hwaddr_t addr, size_t len, uint32_t data);
void cache2_write(hwaddr_t addr, size_t len, uint32_t data);
void cache_init();

#endif